﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Hangjing.SQLServerDAL;
using Hangjing.Model;
using Hangjing.Common;
using Hangjing.WebCommon;
using Newtonsoft.Json;

namespace Html5
{
    public partial class showtogoorder_shop : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                GetData();
            }
        }


        void GetData()
        {
            string id = HjNetHelper.GetQueryString("id");
            CustorderInfo model = new Custorder().GetModel(id);

            IList<OrderPromotionInfo> promotions = new OrderPromotion().GetList(10, 1, "revevar2 = '" + model.orderid + "'", "pid", 1);
            model.Promotions = promotions;

            IList<CustorderInfo> list = new List<CustorderInfo>();
            list.Add(model);
            WebUtility.BindRepeater(rptorder, list);
            WebUtility.BindRepeater(rptorder1, list);
            WebUtility.BindRepeater(rptorder2, list);

            WebUtility.BindRepeater(rptppt, new OrderStep().GetOrderSteps(model.orderid));


            WebUtility.BindRepeater(rptfood, new Foodlist().GetAllByOrderID(id));

            IList<PointsInfo> shop = new Points().GetList(1, 1, "unid=" + model.TogoId, "unid", 1);
    

            this.hState.Value = model.OrderStatus.ToString() ;

            hflatlng.Value = model.ReveVar2;

            if ( model.OrderStatus == 7 && model.deliverid > 0)
            {
                IList<GPS_RecordsInfo> gps = new GPS_Records().GetList(1, 1, "jh1=" + model.deliverid, "id", 1);
                if (gps.Count > 0)
                {
                    hfdeliverlatlng.Value = JsonConvert.SerializeObject(gps);
                }
            }

        }


        /// <summary>
        /// 取消订单
        /// </summary>
        protected void upStatus_Click(object sender, EventArgs e)
        {

            Custorder bll = new Custorder();
            string orderid = HjNetHelper.GetQueryString("id");


            shopSetOrder set = new shopSetOrder(Context, UserHelp.GetUser_Togo().Unid, orderid, 2, "商家取消");
            int rs = set.HandleOrder();

            int msgtag = 1;

            if (rs == 0)
            {
                msgtag = 3;
            }
            else
            {
                msgtag = 2;
            }


            string url = "showtogoorder.aspx?id=" + orderid+"&msg="+ msgtag;


            Response.Redirect(url);

        }


    }
}
